package com.gexin.model.notice;

import com.gexin.common.utils.SQLUtils;
import com.gexin.model.notice.base.BaseNoticePlacard;
import com.jfinal.plugin.activerecord.Page;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * 业务名称:  t_notice_placard(公告表) 
 */
@SuppressWarnings("serial")
public class NoticePlacard extends BaseNoticePlacard<NoticePlacard> {
	public static final NoticePlacard dao = new NoticePlacard();
	//公告表状态  正常
	public static Integer STATEEFFECT =0;
	//公告表状态  禁用
	public static Integer STATEFAIL =1;

	public Page<NoticePlacard> query(int pageNumber,int pageSize,NoticePlacard placard){
		List<Object> list =new LinkedList<Object>();
		SQLUtils sql=new SQLUtils(" from t_notice_placard p left join t_notice_type t on t.id =p.type_id where 1=1 ");
		if(placard!=null){
			if(!StringUtils.isEmpty(placard.getTitle())){
				sql.append(" and p.title like ? ");
				list.add("%"+placard.getTitle()+"%");
			}
			if(placard.getTypeId()!=null){
				sql.append(" and p.type_id = ? ");
				list.add(placard.getTypeId());
			}
			if(placard.getState()!=null){
				sql.append(" and p.state = ? ");
				list.add(placard.getState());
			}
		}
		sql.append(" order by p.create_time desc ");
		return paginate(pageNumber,pageSize,"select p.*,t.type_name ",sql.toString(),list.toArray());
	}
}
